/*
 * StopwatchDelegate.h
 *
 *  Created on: Mar 26, 2012
 *      Author: soniclin
 */

#ifndef STOPWATCH_DELEGATE_H
#define STOPWATCH_DELEGATE_H

#include <ctime>
#include <vector>
#include <iostream>

namespace ibm
{

template<typename T>
class StopwatchDelegate
{
public:

	friend std::ostream& (::operator<<)(std::ostream& os, StopwatchDelegate<T> const& stopwatch);

	StopwatchDelegate();

	virtual ~StopwatchDelegate();

public:

	std::clock_t const& start();

	std::clock_t const& record();

	std::clock_t const& record(unsigned& checkPoint);

	unsigned size() const;

	void history() const;

	std::clock_t getLastTimeDifference() const;

	std::clock_t getDifferenceWithCheckPoint(unsigned const& checkPoint) const;

	static T clocksPerSecond();

private:

	std::vector<clock_t> timeNodes;

};

} // namespace ibm

template<typename T> inline
std::ostream& operator<<(std::ostream& os, ibm::StopwatchDelegate<T> const& stopwatch)
{
	os << static_cast<T>(stopwatch.getLastTimeDifference())/static_cast<T>(CLOCKS_PER_SEC) << " second ";
	return os;
}



#endif /* STOPWATCH_DELEGATE_H */
